<template>
  <div class="app-container">
    <div style="display: flex; justify-content: space-between">
      <div style="display: flex">
        <el-form-item label="材料名称" style="font-size: 15px; height: 40px; display: flex; align-items: center">
          <el-tooltip :content="InputDateList.input1" placement="top">
            <el-input v-model="InputDateList.input1" style="width: 303px; height: 40px; margin-top: 5px" :disabled="true" />
          </el-tooltip>
        </el-form-item>

        <el-form-item label="材料颜色" style="font-size: 15px; height: 40px; display: flex; align-items: center; margin-left: 10px">
          <el-tooltip :content="InputDateList.input2" placement="top">
            <el-input v-model="InputDateList.input2" style="width: 100px; height: 40px; margin-top: 5px" :disabled="true" />
          </el-tooltip>
        </el-form-item>

        <el-form-item label="规格" style="font-size: 15px; height: 40px; display: flex; align-items: center; margin-left: 10px">
          <el-input v-model="InputDateList.input3" style="width: 100px; height: 40px; margin-top: 5px" />
        </el-form-item>

        <el-form-item label="单位" style="font-size: 15px; height: 15px; margin-left: 30px; margin-top: 5px">
          <el-select v-model="InputDateList.input4" class="m-2" placeholder="选择框" size="large">
            <el-option v-for="item in options" :key="item.mtlUnit" :label="item.mtlUnit" :value="item.mtlUnit" />
          </el-select>
        </el-form-item>
      </div>

      <Find :searchImg="false" :OriginalFilter="{ static: true }" :formList="formList1" @findClicked="findData" @Launchform="Launchform" />
    </div>

    <el-card style="margin-top: 10px" shadow="always" :body-style="{ padding: '5px' }">
      <div style="display: flex">
        <div style="width: 50%">
          <h1>贴合材料建档</h1>
          <beiyong
            @currentRow="currentRow"
            :isLoading="isLoading2"
            :tableHeader="tableHeader"
            :tableData="MethodOfBondingMaterialTableDateList"
            :TableHeight="100"
            :outTableHeight="20"
            :getTableList="MethodOfBondingMaterial"
            @currentRow1="currentRow3"
          />
        </div>
        <!-- <div class="flex" style="flex-direction: column; justify-content: center;margin-top: -200px;">
        <el-button @click="choose = 0, TopGoBootom()" type="primary" size="default" class="ml12" style="width: 40px;">
          <span class="svg-container">
            <svg-icon name="ele-Top" style="color: white; font-size: 22px;" />
          </span>
        </el-button>
        <el-button type="primary" size="default" class="ml12 mt30" style="width: 40px;"
          @click="choose = 1, TopGoBootom()">
          <span class="svg-container">
            <svg-icon name="ele-Bottom" style="color: white; font-size: 22px;" />
          </span>
        </el-button>
      </div> -->

        <div style="width: 49%; margin-left: 5px">
          <div style="display: flex; align-items: center">
            <span
              style="
                width: 56px;
                margin-top: 10px;
                margin-right: 10px;
                height: 22px;
                font-family: Inter, Inter;
                font-weight: 500;
                font-size: 14px;
                color: #303133;
                line-height: 22px;
                text-align: left;
                font-style: normal;
                text-transform: none;
              "
              >查询条件</span
            >
            <Find :searchImg="false" :OriginalFilter="{ static: true }" :formList="formList2" @findClicked="findData" @Launchform="Launchform" />
          </div>

          <div style="width: 100%; margin-left: 10px; margin-top: 5px">
            <h1 style="color: red; background-color: #ebeef5">正式材料</h1>
            <beiyong
              :isLoading="isLoading1"
              :tableHeader="tableHeader1"
              :tableData="FormalMaterialsAndMethodsForDevelopingTableDateList.officialMaterials.adhesiveMaterialList"
              :TableHeight="50"
              :outTableHeight="60"
              @currentRow1="currentRow1"
            />
            <PageModule
              style="margin-left: 10px"
              :PageData="{ buttonS: true, total: totalT, pageSizeShow: true }"
              @pageChange="handleSizeChange"
              @pageSizeChange="handleCurrentChange"
            />
          </div>
          <div style="width: 100%; margin-top: 20px">
            <h1 style="color: red; background-color: #ebeef5">开发材料</h1>
            <beiyong
              :isLoading="isLoading"
              :tableHeader="tableHeader2"
              :tableData="FormalMaterialsAndMethodsForDevelopingTableDateList.developmentMaterials.developmentMaterialsList"
              :TableHeight="50"
              :outTableHeight="230"
              @currentRow1="currentRow1"
            />
            <PageModule
              :PageData="{ buttonS: true, total, pageSizeShow: true }"
              @pageChange="handleSizeChange1"
              @pageSizeChange="handleCurrentChange1"
            />
          </div>
        </div>
      </div>

      <!-- 取型体弹窗 -->
      <el-drawer v-model="drawer" :direction="'ttb'" size="small" :with-header="false">
        <span @click="drawer = false" style="float: right; cursor: pointer; color: rgb(7, 7, 7)">X</span>
        <Find :OriginalFilter="{ static: true }" :searchImg="false" :formList="formList" @Launchform="Launchform1" @findClicked="findData1" />
        <h5 style="font-size: 16px; margin-top: 12px">颜色明细</h5>
        <Table
          style="width: 60%"
          :tableData="ColorAcquisitionTableDateList.colorSystemList"
          :tableHeader="tableHeader3"
          :TableHeight="80"
          :isLoading="isLoading3"
          @currentRow1="currentRowToclk"
        />
        <PageModule
          style="width: 60%"
          :PageData="{ buttonS: true, total: totalKlt, pageSizeShow: true }"
          @pageChange="handleSizeChange2"
          @pageSizeChange="handleCurrentChange2"
        />
      </el-drawer>
    </el-card>
  </div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import SynchronizationLoginWork from '@/utils/SynchronizationLoginWork'
import JMessage from '@/utils/JMessage'
export default defineComponent({
  name: 'LaminatedMaterialFile'
})
</script>
<script lang="ts" setup>
import { i18n, Jzhcn } from '@/i18n'
import { ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import { ElMessageBox } from 'element-plus'
import { useRouter } from 'vue-router'
import {
  colourCcheme,
  ListOfFitMaterials,
  ListOfFitAddList,
  FormalMaterialsAndDevelopmentMaterials,
  FitMaterialProfileDeleted,
  chooseAColor,
  ObtainVendor,
  Fluctuation,
  TheCompositeMaterialIsFormed,
  InsertTheBondingMaterialList,
  LaminatedMaterialFile
} from '@/api/ControlDepartment/MaterialManagement/LaminatedMaterialFile'
import type {
  ListOfFitMaterialsInterface,
  ListOfFitAddListInterface,
  FormalMaterialsAndDevelopmentMaterialsParms,
  FormalMaterialsAndDevelopmentMaterialsInterface,
  chooseAColorInterface,
  chooseAColorParms,
  InsertTheBondingMaterialParms
} from '@/api/ControlDepartment/MaterialManagement/LaminatedMaterialFile'
import { FitProcessingMethod, UnitDefinition } from '@/api/ControlDepartment/MaterialManagement/MaterialAttributeDefinition'
import type { FitProcessingMethodInterface } from '@/api/ControlDepartment/MaterialManagement/MaterialAttributeDefinition'

const formList1 = ref([
  // {
  //   type: 'input',
  //   inputPlaceholder: '请输入物料编码',
  //   inputValue: ''
  // },
  // {
  //   type: 'input',
  //   inputPlaceholder: '请输入名称1',
  //   inputValue: ''
  // },
  // {
  //   type: 'input',
  //   inputPlaceholder: '请输入名称2',
  //   inputValue: ''
  // },
  // {
  //   type: 'input',
  //   inputPlaceholder: '请输入名称3',
  //   inputValue: ''
  // },
  // {
  //   type: 'input',
  //   inputPlaceholder: '请输入颜色',
  //   inputValue: ''
  // },
  // {
  //   type: 'input',
  //   inputPlaceholder: '请输入供应商',
  //   inputValue: ''
  // },
  {
    type: 'button',
    checkboxLabel: '组成贴合材料',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '插入贴合材料',
    bgColor: '#FFFFFF',
    color: '#606266',
    borderColor: '#DCDFE6'
  },
  {
    type: 'button',
    checkboxLabel: '物料属性定义',
    bgColor: '#FFFFFF',
    color: '#606266',
    borderColor: '#DCDFE6'
  },
  {
    type: 'button',
    checkboxLabel: '删除插入贴合材料'
  },
  {
    type: 'button',
    checkboxLabel: '保存',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '上移',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '下移',
    bgColor: '#1890FF'
  }
  // {
  //   type: 'button',
  //   checkboxLabel: '置空',
  //   bgColor:'#1890FF',
  // },
])

const formList2 = ref([
  {
    type: 'input',
    inputPlaceholder: '物料编码',
    inputValue: '',
    inputWidth: '86px'
  },
  {
    type: 'input',
    inputPlaceholder: '名称1',
    inputValue: '',
    inputWidth: '86px'
  },
  {
    type: 'input',
    inputPlaceholder: '名称2',
    inputValue: '',
    inputWidth: '86px'
  },
  {
    type: 'input',
    inputPlaceholder: '名称3',
    inputValue: '',
    inputWidth: '86px'
  },
  {
    type: 'input',
    inputPlaceholder: '颜色',
    inputValue: '',
    inputWidth: '86px'
  },
  {
    type: 'input',
    inputPlaceholder: '供应商',
    inputValue: '',
    inputWidth: '86px'
  },
  // {
  //   type: 'button',
  //   checkboxLabel: '组成贴合材料',
  //   bgColor:'#1890FF',
  // },
  // {
  //   type: 'button',
  //   checkboxLabel: '插入贴合材料',
  //   bgColor:'#FFFFFF',
  //   color:'#606266',
  //   borderColor:'#DCDFE6'
  // },
  // {
  //   type: 'button',
  //   checkboxLabel: '物料属性定义',
  //   bgColor:'#FFFFFF',
  //   color:'#606266',
  //   borderColor:'#DCDFE6'
  // },
  // {
  //   type: 'button',
  //   checkboxLabel: '删除插入贴合材料',
  // },
  // {
  //   type: 'button',
  //   checkboxLabel: '保存',
  //   bgColor:'#1890FF',
  // },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  }
])

const formList = ref([
  {
    type: 'select',
    selectValue: '',
    selectP: '色系',
    selectOptions: []
  },
  {
    type: 'input',
    inputPlaceholder: '颜色',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: 'PANTONE',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '颜色(英)',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '颜色定义'
  }
])

const InputDateList = ref({
  input1: '',
  input2: '',
  input3: '',
  input4: ''
})

const drawer = ref(false)

const Vendor = ref<any>()

const options = ref()

// 色系
const EvaluatesTheArrayReturnValue = (ArrayList: any) => {
  return ArrayList.map((item: any, index: any) => {
    return {
      optionKey: index,
      optionValue: item,
      optionLabel: item
    }
  })
}

const colourCchemeMethods = async () => {
  const result = await colourCcheme()
  formList.value[0].selectOptions = EvaluatesTheArrayReturnValue(result)
}

// 插入贴合材料
const InsertTheBondingMaterialMethodsParms = ref<InsertTheBondingMaterialParms>({
  ids: [],
  cacheVoRequests: []
})

const NeaArrayList = ref<any>()

const InsertTheBondingMaterialMethods = async () => {
  InsertTheBondingMaterialMethodsParms.value.ids = MethodOfBondingMaterialTableDateList.value!.map((item: any) => {
    return item.id
  })
  const mergedObject = {
    ids: [],
    mtlColor: InputDateList.value.input2,
    mtlName: InputDateList.value.input1,
    mtlSpec: InputDateList.value.input3,
    mtlUnit: InputDateList.value.input4,
    cacheVoRequests: []
  }
  mergedObject.ids = InsertTheBondingMaterialMethodsParms.value.ids as any

  mergedObject.cacheVoRequests = NeaArrayList.value.map((item: any) => {
    item.prdType = item.prdType.selectValue
    item.vendor = item.vendor.selectValue

    if (item.purFlag) {
      item.purFlag = 'Y'
    }
    return item
  }) as any
  const result = await InsertTheBondingMaterialList(mergedObject as any)
  if (result.code === 200) {
    MethodOfBondingMaterial()
    FormalMaterialsAndMethodsForDevelopingMaterials()
    ;(InputDateList.value.input1 = ''), (InputDateList.value.input2 = ''), (InputDateList.value.input3 = ''), (InputDateList.value.input4 = '')
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

// 单位定义
const UnitDefinitionAddList = async () => {
  const result = await UnitDefinition()
  options.value = result
}

// 组成贴合材料
const MaterialsMathods = async () => {
  const result = await TheCompositeMaterialIsFormed(
    MethodOfBondingMaterialTableDateList.value!.map((item: any) => {
      // 创建一个新的对象，将原对象的属性复制到新对象中
      const newItem = { ...item }

      // 删除新对象的 "change" 属性
      delete newItem.change
      delete newItem.mtlSeq

      // 修改其他属性
      newItem.prdType = item.prdType.selectValue
      newItem.vendor = item.vendor.selectValue
      newItem.purFlag = item.purFlag === true ? 'Y' : ''

      return newItem
    })
  )

  InputDateList.value.input1 = result.data.mtlName
  InputDateList.value.input2 = result.data.mtlColor
  InputDateList.value.input3 = result.data.mtlSpec
  InputDateList.value.input4 = result.data.mtlUnit
  if (result.code === 200) {
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

// 上下移动
const idList = ref()

const choose = ref()

const TopGoBootom = async () => {
  if (idList.value === undefined) {
    JMessage.warning('请选择需要移动的行')
  } else {
    const result = await Fluctuation(choose.value, idList.value)
    if (result.code === 200) {
      MethodOfBondingMaterial()
      JMessage.success(result.message)
    } else {
      JMessage.error(result.message)
    }
  }
}

// 获取贴合加工方式
const FitProcessingMethodTableDateList = ref<FitProcessingMethodInterface[]>()

const FitProcessing = async () => {
  const result = await FitProcessingMethod()
  FitProcessingMethodTableDateList.value = result
}

// 获取厂商
const ObtainVendorTableDateList = async () => {
  const result = await ObtainVendor()
  if (result.code === 200) {
    Vendor.value = result.data
    MethodOfBondingMaterial()
  }
}

// 收集需要修改的数据
const modificationColor = ref<any>()

const currentRow3 = (row: any) => {
  drawer.value = true
  ColorAcquisition()
  colourCchemeMethods()
  modificationColor.value = row
}

const isLoading = ref(true)

const isLoading1 = ref(true)

const isLoading2 = ref(true)

const isLoading3 = ref(true)

// 颜色修改
const currentRowToclk = (row: any) => {
  const { colorName } = row
  modificationColor.value.mtlColor = colorName
  // confirmChange5(modificationColor.value)
  drawer.value = false
}

// 颜色获取
const ColorAcquisitionParms = ref<chooseAColorParms>({
  colorName: '',
  colorSystem: '',
  engColor: '',
  pageNum: 1,
  pageSize: 40,
  pantone: ''
})

const ColorAcquisitionTableDateList = ref<chooseAColorInterface>({
  colorSystemList: []
})

const ColorAcquisition = async () => {
  const result = await chooseAColor(ColorAcquisitionParms.value)
  ColorAcquisitionTableDateList.value.colorSystemList = result.colorSystemList
  totalKlt.value = result.total!
  isLoading3.value = false
}

// 修改贴合材料
// const confirmChange5 = async (row?: any) => {
//   delete row.change
//   delete row.purFlag
//   row.prdType = row.prdType.selectValue
//   row.vendor = row.vendor.selectValue.split(' ')[1]
//   const result = await SynchronizationLoginWork.put<any, any>('/date/getCacheUpdate', row)
//   if (result.code === 200) {
//     JMessage.success(result.message)
//     MethodOfBondingMaterial()
//   } else {
//     JMessage.error(result.message)
//   }
// }

// const change = async (row: any, prop: any) => {
//   delete prop.change;
//   prop.purFlag = prop.purFlag === true ? 'Y' : '';
//   prop.vendor = prop.vendor.selectValue
//   prop.prdType = prop.prdType.selectValue
//   const result = await SynchronizationLoginWork.put<any, any>('/date/getCacheUpdate', prop)
//   if (result.code === 200) {
//     JMessage.success(result.message)
//     MethodOfBondingMaterial()
//   } else {
//     JMessage.error(result.message)
//   }
// }

// 删除插入贴合材料方法
const TheFitMaterialIsRemovedDeleteParms = ref<any>('')

const handleCloseMateriaLKlc1 = (_done?: () => void) => {
  ElMessageBox.confirm('确定要删除该插入贴合材料吗?')
    .then(async () => {
      TheFitMaterialIsRemoved()
    })
    .catch(() => {})
}

const TheFitMaterialIsRemoved = async () => {
  const result = await FitMaterialProfileDeleted([TheFitMaterialIsRemovedDeleteParms.value])
  if (result.code === 200) {
    TheFitMaterialIsRemovedDeleteParms.value = ''
    JMessage.success(result.message)
    MethodOfBondingMaterial()
  } else {
    JMessage.error(result.message)
  }
}

const currentRow = (row: any) => {
  const { id } = row
  TheFitMaterialIsRemovedDeleteParms.value = id
  idList.value = id
}

// 双击添加
const currentRow1 = (row: any) => {
  const { mtlColor, mtlName, mtlNo, mtlSpec, mtlUnit, vendor } = row
  MethodOfBondingAddParmsList.value.mtlColor = mtlColor
  MethodOfBondingAddParmsList.value.mtlName = mtlName
  MethodOfBondingAddParmsList.value.mtlNo = mtlNo
  MethodOfBondingAddParmsList.value.mtlSpec = mtlSpec
  MethodOfBondingAddParmsList.value.mtlUnit = mtlUnit
  MethodOfBondingAddParmsList.value.vendor = vendor
  handleCloseMateriaLKlc()
}

const handleCloseMateriaLKlc = (_done?: () => void) => {
  ElMessageBox.confirm('确定要插入子材料吗?')
    .then(async () => {
      MethodOfBondingAdd()
    })
    .catch(() => {})
}

// 正式材料和开发材料
const FormalMaterialsAndMethodsForDevelopingTableDateList = ref<FormalMaterialsAndDevelopmentMaterialsParms>({
  officialMaterials: {
    adhesiveMaterialList: []
  },
  developmentMaterials: {
    developmentMaterialsList: []
  }
})

const FormalMaterialsAndMethodsForDevelopingMaterialsParms = ref<any>({
  mtlColor: '',
  mtlName: '',
  mtlNo: '',
  pageNum: 1,
  pageNum2: 1,
  pageSize: 40,
  pageSize2: 40,
  vendor: '',
  mtlName2: '',
  mtlName3: ''
})

const FormalMaterialsAndMethodsForDevelopingMaterials = async () => {
  const result = await FormalMaterialsAndDevelopmentMaterials(FormalMaterialsAndMethodsForDevelopingMaterialsParms.value)
  total.value = result.developmentMaterials.total!
  totalT.value = result.officialMaterials.total!
  FormalMaterialsAndMethodsForDevelopingTableDateList.value.developmentMaterials.developmentMaterialsList =
    result.developmentMaterials.developmentMaterialsList
  FormalMaterialsAndMethodsForDevelopingTableDateList.value.officialMaterials.adhesiveMaterialList = result.officialMaterials.adhesiveMaterialList
  isLoading.value = false
  isLoading1.value = false
}

// 贴合材料建档列表添加
const MethodOfBondingAddParmsList = ref<ListOfFitAddListInterface>({
  mtlColor: '',
  mtlName: '',
  mtlNo: '',
  mtlSpec: '',
  mtlUnit: '',
  vendor: ''
})

const MethodOfBondingAdd = async () => {
  const result = await ListOfFitAddList(MethodOfBondingAddParmsList.value)
  if (result.code === 200) {
    JMessage.success(result.message)
    MethodOfBondingMaterial()
  } else {
    JMessage.error(result.message)
  }
}

// 贴合材料建档列表
const MethodOfBondingMaterialTableDateList = ref<ListOfFitMaterialsInterface[]>()

const MethodOfBondingMaterial = async () => {
  isLoading2.value = true
  const result = await ListOfFitMaterials()
  if (result.length !== 0) {
    MethodOfBondingMaterialTableDateList.value = result.map((item: any) => {
      item.disableConfirm = true
      if (Vendor.value) {
        item.vendor = {
          selectValue: item.vendor || '',
          options: Vendor.value.map((item1: any, index: any) => {
            if (item1 === null) return
            return {
              label: item1.vendorName,
              value: `${item1.vendorNo} ${item1.vendorName}`,
              LeftLabel: item1.vendorNo,
              RightLabel: item1.vendorName
            }
          })
        }
      }

      if (FitProcessingMethodTableDateList.value) {
        item.prdType = {
          selectValue: item.prdType || '',
          options: FitProcessingMethodTableDateList.value!.map((item1: any, index: any) => {
            if (item1 === null) return
            return {
              label: item1.prdType,
              value: item1.prdType,
              LeftLabel: item1.prdType
            }
          })
        }
      }

      if (item.purFlag === 'Y') {
        item.purFlag = true
      }
      item.change = 'Y'
      return item
    })
    NeaArrayList.value = MethodOfBondingMaterialTableDateList.value
  } else {
    MethodOfBondingMaterialTableDateList.value = []
  }
  isLoading2.value = false
}

// 统一调用接口
const interAceFunct = () => {
  // 厂商
  ObtainVendorTableDateList()

  // 正式材料和开发材料
  FormalMaterialsAndMethodsForDevelopingMaterials()

  // 贴合加工方式
  FitProcessing()
}

onMounted(() => {
  interAceFunct()
})

const router = useRouter()

// 表格数据

const tableHeader = ref([
  {
    label: '物料编码',
    prop: 'mtlNo',
    change: true
  },
  {
    label: '材料颜色',
    prop: 'mtlColor',
    change: true
  },
  {
    label: '材料名称',
    prop: 'mtlName',
    change: true
  },
  {
    label: '规格',
    prop: 'mtlSpec',
    change: true
  },
  {
    label: '单位',
    prop: 'mtlUnit',
    change: true
  },
  {
    label: '加工方式',
    prop: 'prdType',
    type: 'select'
  },
  {
    label: '供应商',
    prop: 'vendor',
    type: 'select'
  },
  {
    label: '比例',
    prop: 'percent'
  },
  {
    label: '请购否',
    type: 'checkbox',
    prop: 'purFlag'
  }
])

const tableHeader1 = ref([
  {
    label: '物料编码',
    prop: 'mtlNo'
  },
  {
    label: '材料颜色',
    prop: 'mtlColor'
  },
  {
    label: '材料名称',
    prop: 'mtlName'
  },
  {
    label: '规格',
    prop: 'mtlSpec'
  },
  {
    label: '单位',
    prop: 'mtlUnit'
  },
  {
    label: '供应商',
    prop: 'vendor'
  }
])

const tableHeader2 = ref([
  {
    label: '物料编码',
    prop: 'mtlNo'
  },
  {
    label: '材料颜色',
    prop: 'mtlColor'
  },
  {
    label: '材料名称',
    prop: 'mtlName'
  },
  {
    label: '规格',
    prop: 'mtlSpec'
  },
  {
    label: '单位',
    prop: 'mtlUnit'
  },
  {
    label: '供应商',
    prop: 'vendor'
  }
])

const tableHeader3 = ref([
  {
    label: '色系',
    prop: 'colorSystem'
  },
  {
    label: '颜色',
    prop: 'colorName'
  },
  {
    label: 'PANTONE',
    prop: 'pantone'
  },
  {
    label: '颜色(英)',
    prop: 'engColor'
  }
])

const total = ref(0)

const handleSizeChange = (val: number) => {
  isLoading1.value = true
  FormalMaterialsAndMethodsForDevelopingMaterialsParms.value.pageNum = val
  FormalMaterialsAndMethodsForDevelopingMaterials()
}
const handleCurrentChange = (val: number) => {
  isLoading1.value = true
  FormalMaterialsAndMethodsForDevelopingMaterialsParms.value.pageSize = val
  FormalMaterialsAndMethodsForDevelopingMaterials()
}

const totalT = ref(0)

const handleSizeChange1 = (val: number) => {
  isLoading.value = true
  FormalMaterialsAndMethodsForDevelopingMaterialsParms.value.pageNum2 = val
  FormalMaterialsAndMethodsForDevelopingMaterials()
}

const handleCurrentChange1 = (val: number) => {
  isLoading.value = true
  FormalMaterialsAndMethodsForDevelopingMaterialsParms.value.pageSize2 = val
  FormalMaterialsAndMethodsForDevelopingMaterials()
}

const totalKlt = ref(0)

const handleSizeChange2 = (val: number) => {
  isLoading3.value = true
  ColorAcquisitionParms.value.pageNum = val
  ColorAcquisition()
}

const handleCurrentChange2 = (val: number) => {
  isLoading3.value = true
  ColorAcquisitionParms.value.pageSize = val
  ColorAcquisition()
}

const LaminatedMaterialFileMethods = async () => {
  const result = await LaminatedMaterialFile(
    MethodOfBondingMaterialTableDateList.value?.map((item: any) => {
      item.prdType = item.prdType.selectValue
      item.vendor = item.vendor.selectValue.split(' ')[1]
      item.purFlag = item.purFlag === true ? 'Y' : ''
      return item
    })
  )
  if (result.code === 200) {
    MethodOfBondingMaterial()
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

const findData = (find: string) => {
  if (find === '上移') {
    ;(choose.value = 0), TopGoBootom()
  }
  if (find === '下移') {
    ;(choose.value = 1), TopGoBootom()
  }
  if (find === '保存') {
    LaminatedMaterialFileMethods()
  }
  if (find === '置空') {
    // clearFormList1()
  }
  if (find === '物料属性定义') {
    router.push({
      path: '/ControlDepartment/MaterialManagement/MaterialAttributeDefinition'
    })
  }
  if (find === '删除插入贴合材料') {
    if (TheFitMaterialIsRemovedDeleteParms.value.length !== 0) {
      handleCloseMateriaLKlc1()
    } else {
      JMessage.warning('请选择需要删除的数据')
    }
  }
  if (find === '组成贴合材料') {
    if (MethodOfBondingMaterialTableDateList.value?.length !== 0) {
      MaterialsMathods()
      UnitDefinitionAddList()
    } else {
      JMessage.warning('请选择正确的贴合材料建档')
    }
  }
  if (find === '插入贴合材料') {
    if (InputDateList.value.input1 !== '' || InputDateList.value.input2 !== '' || InputDateList.value.input3 !== '') {
      InsertTheBondingMaterialMethods()
    } else {
      JMessage.warning('请选择正确的贴合材料建档')
    }
  }
}

const clearFormList2 = () => {
  formList.value.forEach((item) => {
    if (item.type === 'input') {
      item.inputValue = ''
    }
    if (item.type === 'select') {
      item.selectValue = ''
    }
    // Add other conditions for different form item types
  })
}

const findData1 = (find: string) => {
  if (find === '颜色定义') {
    router.push({
      path: '/ControlDepartment/MaterialManagement/ColorAttributeDefinition'
    })
  }
  if (find === '置空') {
    clearFormList2()
  }
}

// const clearFormList1 = () => {
//   formList1.value.forEach((item) => {
//     if (item.type === 'input') {
//       item.inputValue = '';
//     }
//     // Add other conditions for different form item types
//   });
// };

const Launchform = (row: any) => {
  isLoading.value = true
  isLoading1.value = true
  FormalMaterialsAndMethodsForDevelopingMaterialsParms.value.mtlNo = row[0].inputValue
  FormalMaterialsAndMethodsForDevelopingMaterialsParms.value.mtlName = row[1].inputValue
  FormalMaterialsAndMethodsForDevelopingMaterialsParms.value.mtlName2 = row[2].inputValue
  FormalMaterialsAndMethodsForDevelopingMaterialsParms.value.mtlName3 = row[3].inputValue
  FormalMaterialsAndMethodsForDevelopingMaterialsParms.value.mtlColor = row[4].inputValue
  FormalMaterialsAndMethodsForDevelopingMaterialsParms.value.vendor = row[5].inputValue

  FormalMaterialsAndMethodsForDevelopingMaterials()
}

const Launchform1 = (row: any) => {
  isLoading3.value = true
  ColorAcquisitionParms.value.colorSystem = row[0].selectValue
  ColorAcquisitionParms.value.colorName = row[1].inputValue
  ColorAcquisitionParms.value.pantone = row[2].inputValue
  ColorAcquisitionParms.value.engColor = row[3].inputValue
  ColorAcquisition()
}
</script>

<style lang="less" scoped>
h1 {
  font-size: 16px;
}
</style>
